package com.fesine.ssh.model;

/**
 * Created by Fesine on 2016/2/21.
 */

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.util.HashSet;
import java.util.Set;

/**
 * 产品分类
 *
 * @author fesine
 */
@Entity
@Table(name = "t_category")
public class Category extends BasePo {
    /**
     * 分类的id
     */
    @Column(name="cateId" ,unique = true)
    private int cateId;
    /**
     * 分类名称
     */
    private String text;
    /**
     * 分类描述
     */
    private String description;
    /**
     * 父节点的id
     */
    private Integer parent;//
    /**
     * true为叶子,false为非叶子
     */
    private Integer leaf;
    /**
     * 一个类中包含的产品(一对多的关系)
     */
    private Set<Product> products = new HashSet<>();


    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Integer getParent() {
        return parent;
    }

    public void setParent(Integer parent) {
        this.parent = parent;
    }

    public Integer getLeaf() {
        return leaf;
    }

    public void setLeaf(Integer leaf) {
        this.leaf = leaf;
    }

    @OneToMany(mappedBy = "category")
    @Cascade(CascadeType.ALL)//级连删除
    public Set<Product> getProducts() {
        return products;
    }

    public void setProducts(Set<Product> products) {
        this.products = products;
    }

    public int getCateId() {
        return cateId;
    }

    public void setCateId(int cateId) {
        this.cateId = cateId;
    }
}
